﻿namespace IPMS.BLL
{
    using IPMS.DAL;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class ProductProject
    {
        private string _CreateBy;
        private string _Model;
        private string _OwnerGroupID;
        private string _ProjectCode;
        private string _UpdateBy;

        public ProductProject(string model, string projectCode, string createBy, string updateBy, string ownerGroupId)
        {
            this._Model = model;
            this._ProjectCode = projectCode;
            this._CreateBy = createBy;
            this._UpdateBy = updateBy;
            this._OwnerGroupID = ownerGroupId;
        }

        public int DeleteProductProject()
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Model", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._Model.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._ProjectCode.ToString());
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "DelProductProjectSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }

        public int SetProductProject()
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Model", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._Model.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._ProjectCode.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@CreateBy", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._CreateBy.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@UpdateBy", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._UpdateBy.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@OwnerGroupID", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._OwnerGroupID.ToString());
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "SetProductProjectSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }
    }
}

